<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="CommonUtil/CommonUtil.js"></script>
    <script type="text/javascript" charset="utf-8">
        //装饰者模式
        /**
         * 实现同样的接口，需要有子类
         */
        var CarInterface = new BH.Interface('CarInterface',['getPrice','assemble']);
        var Car = function (car) {
            //让子类继承的，让父类多一个子类的引用
            this.car = car;
            BH.Interface.ensureImplements(this,CarInterface);
        }
        Car.prototype = {
            constructor:Car,
            getPrice:function () {
                return 200000;
            },
            assemble:function () {
                document.write('组装汽车...');
            }
        }
        //新的需求
        var LightDecorator = function (car) {
            //借用构造函数继承
            LightDecorator.superClass.constructor.call(this,car);
        };
        BH.extend(LightDecorator,Car);
        LightDecorator.prototype = {
            constructor:LightDecorator,
            getPrice:function () {
                return this.car.getPrice()+10000;
            },
            assemble:function () {
                document.write('组装车灯...');
            }
        }
        var IceBoxDecorator = function (car) {
            IceBoxDecorator.superClass.constructor.call(this,car);
        }
        BH.extend(IceBoxDecorator,Car);
        IceBoxDecorator.prototype = {
            constructor:IceBoxDecorator,
            getPrice:function () {
                return this.car.getPrice()+20000;
            },
            assemble:function () {
                document.write('组装车载冰箱...');
            }
        }
        var car = new Car();
        alert(car.getPrice());
        car.assemble();
        //car = new LightDecorator(car);
        //alert(car.getPrice());
        //car.assemble();
        car = new IceBoxDecorator(car);
        alert(car.getPrice());
        car.assemble();
    </script>
</head>
<body>
</body>
</html>